<?php
/**
 * Session.class.php
 * - Contain all function proccessing session
 * @since 1.0 - Aug 04, 2011
 * @Id: $
 */
class Session {
	
	/**
     * init
     * - Constructor
     */
    public function __construct() {
    }
	/**
	 * Set
	 * - Use set info for session
	 * @param string $name: name of session
	 * @param $value: info of session
	 */
    public static function Set($name, $value)
    {
        $_SESSION[constants::$SESSION_PREFIX. $name] = $value;
    }
	
	/**
	 * Get
	 * - Use get info of session
	 * @param string $name: name of session
	 * @return array contain info of session
	 */
    public static function Get($name)
    {
        return isset($_SESSION[constants::$SESSION_PREFIX. $name]) ? $_SESSION[constants::$SESSION_PREFIX. $name] : null;
    }
    
    /**
     * Remove
     * - Use unset one session
     * @param string $name: name of session
     */
    public static function Remove($name)
    {
        if (isset($_SESSION[constants::$SESSION_PREFIX. $name]))
        {
            unset($_SESSION[constants::$SESSION_PREFIX. $name]);
        }
    }
    
    /**
     * IsExist
     * - Use check exists one session
     * @param string $name: name of session
     */
    public static function IsExist($name)
    {
        return isset($_SESSION[constants::$SESSION_PREFIX. $name]) ? true: false;
    }
    
    /**
     * GetAllSession
     * - Use get all session
     * @return array contain info of session
     */
    public static function GetAllSession()
    {
        return $_SESSION;
    }
    
    /**
     * RemoveAll
     * - Use remove many session
     * @param string $prefix: SESSION_PREFIX
     */
    public static function RemoveAll($prefix)
    {
        if (! empty ($_SESSION) && is_array($_SESSION))
        {
            foreach ($_SESSION as $key=>$value) {
                if ($prefix && stripos($key, $prefix) !== false)
                {
                    unset ($_SESSION[$key]);
                }
            }
        }
    }
    
    /**
     * DestroyAll
     * - Use destroy all session
     */
    public static function DestroyAll()
    {
        session_destroy();
    }
    
}
?>